package com.kltn.zigo.data.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.kltn.zigo.R;
import com.kltn.zigo.data.loader.ProvinceLoader;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ProvinceAdapter extends BaseAdapter{

	private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    private ProvinceLoader provinceloader;
    
    public ProvinceAdapter(Activity a, ProvinceLoader pl) {
        activity = a;
        data=pl.GetProvince();
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        provinceloader = pl;        
    }
    
    public ProvinceAdapter(Activity a, ProvinceLoader pl, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        provinceloader = pl;  
    }
	
	public int getCount() {
        return data.size();
	}

	public Object getItem(int position) {
        return position;
	}

	public long getItemId(int position) {
        return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item_list_address, null);

        TextView province_id = (TextView)vi.findViewById(R.id.tvID);
        TextView province_name = (TextView)vi.findViewById(R.id.tvProvinceDistrict);
        
        HashMap<String, String> province = new HashMap<String, String>();
        province = data.get(position);
        // Setting all values in listview
        province_id.setText(province.get(provinceloader.TAG_PROVINCE_ID));
        province_name.setText(province.get(provinceloader.TAG_PROVINCE_NAME));
        return vi;
	}
}
